<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>unarray example: unarray_2d_varian &mdash; nmrglue v0.1 documentation</title>
    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '0.1',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="nmrglue v0.1 documentation" href="../index.html" />
    <link rel="up" title="Examples" href="index.html" />
    <link rel="next" title="unarray example: unarray_2d_bruker" href="unarray_2d_bruker.html" />
    <link rel="prev" title="unarray example: unarray_1d_varian" href="unarray_1d_varian.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="unarray_2d_bruker.html" title="unarray example: unarray_2d_bruker"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="unarray_1d_varian.html" title="unarray example: unarray_1d_varian"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">nmrglue v0.1 documentation</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">Examples</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h4>Previous topic</h4>
            <p class="topless"><a href="unarray_1d_varian.html"
                                  title="previous chapter">unarray example: unarray_1d_varian</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="unarray_2d_bruker.html"
                                  title="next chapter">unarray example: unarray_2d_bruker</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/examples/unarray_2d_varian.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="unarray-example-unarray-2d-varian">
<span id="unarray-2d-varian"></span><h1>unarray example: unarray_2d_varian<a class="headerlink" href="#unarray-example-unarray-2d-varian" title="Permalink to this headline">¶</a></h1>
<p>This example shows how to use nmrglue to seperate varian data collected with
an innermost parameter interleaved.  The full experimental data in the
<tt class="docutils literal"><span class="pre">arrayed_data.dir</span></tt> directory is unpacked into a series of directories with
names <tt class="docutils literal"><span class="pre">tXmix_*.fid</span></tt> which can be converted with nmrglue or NMRPipe. The name
and values of the interleaved parameter is determined from the <tt class="docutils literal"><span class="pre">procpar</span></tt>
file in the <tt class="docutils literal"><span class="pre">arrayed_data.dir</span></tt> directory.</p>
<p>[<a class="reference external" href="el/unarray/unarray_2d_varian/unarray.py">source code</a>]</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c">#! /usr/bin/env python</span>
<span class="c"># Unarray 1D varian data creating directories based on array parameter found in</span>
<span class="c"># procpar file.  Directories are named param_value.fid</span>

<span class="kn">import</span> <span class="nn">nmrglue</span> <span class="kn">as</span> <span class="nn">ng</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">shutil</span>

<span class="c"># the directory name of the arrayed data</span>
<span class="n">dirname</span> <span class="o">=</span> <span class="s">&quot;arrayed_data.dir&quot;</span>

<span class="c"># read the fid file and procpar file</span>
<span class="n">fdic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">varian</span><span class="o">.</span><span class="n">read_fid_lowmem</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dirname</span><span class="p">,</span><span class="s">&quot;fid&quot;</span><span class="p">))</span>
<span class="n">dic</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">varian</span><span class="o">.</span><span class="n">read_procpar</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dirname</span><span class="p">,</span><span class="s">&quot;procpar&quot;</span><span class="p">))</span>

<span class="c"># create directory names based of procpar array values</span>
<span class="n">dir_pre</span> <span class="o">=</span> <span class="n">dic</span><span class="p">[</span><span class="s">&quot;array&quot;</span><span class="p">][</span><span class="s">&quot;values&quot;</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="n">dir_mid</span> <span class="o">=</span> <span class="s">&quot;_&quot;</span>
<span class="n">dir_values</span> <span class="o">=</span> <span class="n">dic</span><span class="p">[</span><span class="n">dir_pre</span><span class="p">][</span><span class="s">&quot;values&quot;</span><span class="p">]</span>
<span class="n">dir_post</span> <span class="o">=</span> <span class="s">&quot;.fid&quot;</span>
<span class="n">dir_names</span> <span class="o">=</span> <span class="p">[</span><span class="s">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">dir_pre</span><span class="p">,</span><span class="n">dir_mid</span><span class="p">,</span><span class="n">v</span><span class="p">,</span><span class="n">dir_post</span><span class="p">])</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">dir_values</span><span class="p">]</span>

<span class="c"># update the file header (assumes equal number of blocks in each slice)</span>
<span class="n">fdic</span><span class="p">[</span><span class="s">&quot;nblocks&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">fdic</span><span class="p">[</span><span class="s">&quot;nblocks&quot;</span><span class="p">]</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">dir_names</span><span class="p">)))</span>

<span class="c"># unarray the data</span>
<span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="nb">dir</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">dir_names</span><span class="p">):</span>
    
    <span class="c"># create the directory</span>
    <span class="k">print</span> <span class="s">&quot;Creating:&quot;</span><span class="p">,</span><span class="nb">dir</span>
    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="nb">dir</span><span class="p">)</span><span class="o">==</span><span class="bp">False</span><span class="p">:</span>
        <span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="nb">dir</span><span class="p">)</span>
    
    <span class="c"># copy procpar file to the new directory</span>
    <span class="n">src</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dirname</span><span class="p">,</span><span class="s">&quot;procpar&quot;</span><span class="p">)</span>
    <span class="n">dst</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">dir</span><span class="p">,</span><span class="s">&quot;procpar&quot;</span><span class="p">)</span>
    <span class="n">shutil</span><span class="o">.</span><span class="n">copyfile</span><span class="p">(</span><span class="n">src</span><span class="p">,</span><span class="n">dst</span><span class="p">)</span>

    <span class="c"># slice the data </span>
    <span class="nb">slice</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">::</span><span class="nb">len</span><span class="p">(</span><span class="n">dir_names</span><span class="p">)]</span> 
    
    <span class="c"># filename</span>
    <span class="n">fname</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">dir</span><span class="p">,</span><span class="s">&quot;fid&quot;</span><span class="p">)</span>

    <span class="c"># write out the file</span>
    <span class="n">ng</span><span class="o">.</span><span class="n">varian</span><span class="o">.</span><span class="n">write_fid</span><span class="p">(</span><span class="n">fname</span><span class="p">,</span><span class="n">fdic</span><span class="p">,</span><span class="nb">slice</span><span class="p">,</span><span class="n">overwrite</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="unarray_2d_bruker.html" title="unarray example: unarray_2d_bruker"
             >next</a> |</li>
        <li class="right" >
          <a href="unarray_1d_varian.html" title="unarray example: unarray_1d_varian"
             >previous</a> |</li>
        <li><a href="../index.html">nmrglue v0.1 documentation</a> &raquo;</li>
          <li><a href="index.html" >Examples</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2010, Jonathan J. Helmus.
      Last updated on Apr 04, 2011.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.4.
    </div>
  </body>
</html>